package com.zbl.zblproject.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbl.zblproject.erp.entity.ErpOweGoodsItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/29
 */
@Repository
public interface ErpOweGoodsItemMapper extends BaseMapper<ErpOweGoodsItem> {

    List<String> getOrderSns();

    /**
     * 查询订单号根据OrderSn
     * @param mode
     * @return
     */
    List<String> getOrderSnsByMode(@Param("mode") int mode,@Param("orderSn")String orderSn,@Param("start")String start,@Param("end")String end);

    @Delete("DELETE FROM zbl_erp_owegoodsitem WHERE erp_order_item_id = #{id}")
    boolean deleteByErpItemId(@Param("id") int id);

    @Delete("DELETE FROM zbl_erp_owegoodsitem WHERE item_id = #{id}")
    boolean deleteByItemId(@Param("id") int id);

    @Update("UPDATE zbl_erp_owegoodsitem SET mode = 2 WHERE order_sn = #{orderSn} ")
    boolean changeOrderSn(@Param("orderSn") String orderSn);

    /**
     * 订单MODE设置为 3 设置为终结
     * @param orderSn
     * @return
     */
    @Update("UPDATE zbl_erp_owegoodsitem SET mode = 3,  operator_name = #{userName},  operator_time = #{time} WHERE order_sn = #{orderSn} ")
    boolean changeOrderSnToEnded(@Param("orderSn") String orderSn, @Param("userName") String userName, @Param("time")LocalDateTime time);

    @Select("SELECT * FROM zbl_erp_owegoodsitem WHERE mode != 3 AND number > 0 AND order_sn = #{orderSn}")
    List<ErpOweGoodsItem> selectListByOrderSn(@Param("orderSn") String orderSn);

    @Select("SELECT operator_time FROM zbl_erp_owegoodsitem WHERE order_sn = #{orderSn} LIMIT 1  ")
    LocalDateTime selectLocalDateTimeByOrderSn(@Param("orderSn") String orderSn);

    @Select("SELECT operator_name FROM zbl_erp_owegoodsitem WHERE order_sn = #{orderSn} LIMIT 1 ")
    String selectOperatorByOrderSn(@Param("orderSn") String orderSn);

}
